define(['jquery','jqcookie'],()=>{
    class Header{
        constructor(){
            this.loadHTML().then(()=>{
                this.getcookie()
                this.outcookie()
                this.calcCartCount()
            })
        }
        loadHTML(){
            return new Promise(resolve=>{
                $('header').load('/html/modules/header.html',resolve)    
            })
            
        }
        getcookie(){
            let name = $.cookie('tel')
            $('#teln').text(name)
            if(name){
                $('.h-right').css({
                    "display":"none"
                })
            } 
            
        }
        outcookie(){
            $('#out').on('click',()=>{
                $.removeCookie("tel",{
                    path:'/'
                })
                $('.h-right').css({
                    'display':'block'
                })
            })
        }
        calcCartCount(){
            let count = 0
            let cart = localStorage.getItem('cart')
            if(cart){
                cart = JSON.parse(cart)
                count = cart.reduce((num,shop)=>num+shop.count,0)
            }
            $('.nnum').html(count)
            $('.nnnum').html(count)
        }
    }
    return new Header()
})